/**
 * By wangmingxue
 * Created by wangmingxue on 16/04/26.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'collection',
    'template',
    'model',
    'dialog',
    'fineuploader',
    'calendar'
], function ($, common, ready, Collection, template, Model, dialog, fineuploader, calendar) {
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.fetch();
            this.event();
        },

        fetch: function () {
            var _this = this;
            this.collection = new Collection({
                url: _global.url.api + 'data/homepage_data',
                condition: {limit: 100, offset: 0},
                model: {
                    tag_name: 'tr',
                    url: {},
                    event: {
                    }
                },
                callback: function () {
                    loaded();
                }
            });
            this.collection.fetch();
        },

        event: function () {
            var _this = this;
            //日期
            $('.form_datetime').calendar();
            //按照日期和标签查询
            $('#btn-search').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.tag_id = $('#tag').val();
                _this.collection.condition.type = $('#sort').val();
                _this.collection.condition.date = $('.form_datetime').val();
                _this.collection.reload();
            });

            $.ajax({
                url: _global.url.api + 'data/tag_list',
                type: 'get',
                success: function (res) {
                    console.log(res);
                    $('#tag').append(template('select-item',res))
                }
            })
        }
    };

    new index();

});